import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by admin on 2019/1/20.
 */
public class ThreadPoolExecutorDemo {
    /**
     * 核心线程池大小
     */
    static int corePoolSize = 10;
    /**
     * 线程池最大数量
     */
    static int maximumPoolSizeSize = 200;
    /**
     * 线程活动保持时间
     */
    static long keepAliveTime = 1;

    static AtomicInteger num = new AtomicInteger(0);
    /**
     * 任务队列
     */
    static ArrayBlockingQueue workQueue = new ArrayBlockingQueue(10);

    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                corePoolSize,
                maximumPoolSizeSize,
                keepAliveTime,
                TimeUnit.SECONDS,
                workQueue,
                new ThreadPoolExecutor.DiscardPolicy());
        //提交一个任务
        Runnable runnable = new Runnable() {
            public void run() {
                System.out.println(Thread.currentThread().getName() + "在执行任务" + num.addAndGet(1));
            }
        };
        for (int i = 0; i < 200; i ++) {
            executor.execute(runnable);
        }
        executor.shutdown();
        //executor.shutdownNow();
    }
}
